package com.example.tongue.ui.Online.Body;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.example.tongue.ui.Online.Body.utils.ScoreCalculationSeven;
import com.example.tongue.R;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class YangDeficiency extends Activity implements View.OnClickListener {
    private Button next3,whetherYang;
    private RadioGroup coldHandsAndFeet,gastricCavity,wearMuchClothes,
            fanAirConditioner,easyCold,coldAndDiarrhea,afraidOfCold;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.yangdeficiency);
        //控件绑定资源
        next3=findViewById(R.id.Next3);


                coldHandsAndFeet=findViewById(R.id.ColdHandsAndFeet);
                gastricCavity=findViewById(R.id.GastricCavity);
                wearMuchClothes=findViewById(R.id.WearMuchClothes);
                fanAirConditioner=findViewById(R.id.FanAirConditioner);
                easyCold=findViewById(R.id.EasyCold);
                coldAndDiarrhea=findViewById(R.id.ColdAndDiarrhea);
                afraidOfCold=findViewById(R.id.AfraidOfCold);
        //设置监听器
        next3.setOnClickListener(this);

                coldHandsAndFeet.setOnClickListener(this);
                gastricCavity.setOnClickListener(this);
                wearMuchClothes.setOnClickListener(this);
                fanAirConditioner.setOnClickListener(this);
                easyCold.setOnClickListener(this);
                coldAndDiarrhea.setOnClickListener(this);
                afraidOfCold.setOnClickListener(this);






    }

    @Override
    public void onClick(View v) {
        switch(v.getId()){

            case R.id.Next3:{
                //计算结果,把结果写入缓存
                YangResult();
//                Toast.makeText(YangDeficiency.this, "进入痰湿质判断", Toast.LENGTH_SHORT).show();
                startActivity(new Intent(YangDeficiency.this,PhlegmQuality.class));
            }
            break;


        }

    }
    public void YangResult(){
        int coldHandsAndFeetid= coldHandsAndFeet.getCheckedRadioButtonId();
        RadioButton coldHandsAndFeetbtn= findViewById(coldHandsAndFeetid);
        String coldHandsAndFeetfin=coldHandsAndFeetbtn.getText().toString();

        int  gastricCavityid= gastricCavity.getCheckedRadioButtonId();
        RadioButton gastricCavitybtn= findViewById(gastricCavityid);
        String gastricCavityfin=gastricCavitybtn.getText().toString();

        int wearMuchClothesid= wearMuchClothes.getCheckedRadioButtonId();
        RadioButton wearMuchClothesbtn= findViewById(wearMuchClothesid);
        String  wearMuchClothesfin= wearMuchClothesbtn.getText().toString();

        int fanAirConditionerid= fanAirConditioner.getCheckedRadioButtonId();
        RadioButton fanAirConditionerbtn= findViewById(fanAirConditionerid);
        String fanAirConditionerfin=fanAirConditionerbtn.getText().toString();

        int easyColdid=easyCold.getCheckedRadioButtonId();
        RadioButton easyColdbtn= findViewById(easyColdid);
        String easyColdfin=easyColdbtn.getText().toString();


        int afraidOfColdid= afraidOfCold.getCheckedRadioButtonId();
        RadioButton afraidOfColdbtn= findViewById(afraidOfColdid);
        String afraidOfColdfin=afraidOfColdbtn.getText().toString();

        int coldAndDiarrheaid=coldAndDiarrhea.getCheckedRadioButtonId();
        RadioButton coldAndDiarrheabtn= findViewById(coldAndDiarrheaid);
        String coldAndDiarrheafin=coldAndDiarrheabtn.getText().toString();




        Map<String,Integer>   coldHandsAndFeetMap=new HashMap<String,Integer>();
        coldHandsAndFeetMap.put("没有",1);
        coldHandsAndFeetMap.put("很少",2);
        coldHandsAndFeetMap.put("有时",3);
        coldHandsAndFeetMap.put("常常",4);
        coldHandsAndFeetMap.put("经常",5);

        Map<String,Integer> gastricCavityMap=new HashMap<String,Integer>();
        gastricCavityMap.put("没有",1);
        gastricCavityMap.put("很少",2);
        gastricCavityMap.put("有时",3);
        gastricCavityMap.put("常常",4);
        gastricCavityMap.put("经常",5);

        Map<String,Integer>   wearMuchClothesMap=new HashMap<String,Integer>();
        wearMuchClothesMap.put("没有",1);
        wearMuchClothesMap.put("很少",2);
        wearMuchClothesMap.put("有时",3);
        wearMuchClothesMap.put("常常",4);
        wearMuchClothesMap.put("经常",5);

        Map<String,Integer>  fanAirConditionerMap=new HashMap<String,Integer>();
        fanAirConditionerMap.put("没有",1);
        fanAirConditionerMap.put("很少",2);
        fanAirConditionerMap.put("有时",3);
        fanAirConditionerMap.put("常常",4);
        fanAirConditionerMap.put("经常",5);

        Map<String,Integer> easyColdMap=new HashMap<String,Integer>();
        easyColdMap.put("没有",1);
        easyColdMap.put("很少",2);
        easyColdMap.put("有时",3);
        easyColdMap.put("常常",4);
        easyColdMap.put("经常",5);

        Map<String,Integer> afraidOfColdMap=new HashMap<String,Integer>();
        afraidOfColdMap.put("没有",1);
        afraidOfColdMap.put("很少",2);
        afraidOfColdMap.put("有时",3);
        afraidOfColdMap.put("常常",4);
        afraidOfColdMap.put("经常",5);

        Map<String,Integer> coldAndDiarrheaMap=new HashMap<String,Integer>();
        coldAndDiarrheaMap.put("没有",1);
        coldAndDiarrheaMap.put("很少",2);
        coldAndDiarrheaMap.put("有时",3);
        coldAndDiarrheaMap.put("常常",4);
        coldAndDiarrheaMap.put("经常",5);





        Integer yaResult =coldHandsAndFeetMap.get(coldHandsAndFeetfin)+
                gastricCavityMap.get(gastricCavityfin) +
                wearMuchClothesMap.get( wearMuchClothesfin) +
                fanAirConditionerMap.get(fanAirConditionerfin)+
                easyColdMap.get(easyColdfin)+
                afraidOfColdMap.get(afraidOfColdfin)+
                coldAndDiarrheaMap.get(coldAndDiarrheafin);

        ScoreCalculationSeven  scoreCalculationSeven=new ScoreCalculationSeven(yaResult);
        String ConversionScore=scoreCalculationSeven.getResult();
        TextView yangresult=(TextView)findViewById(R.id.YangResult);
        yangresult.setText("阳虚质结果:"+ConversionScore);

        File dataFileDir=new File(getExternalCacheDir(),"PhysiqueDataFile");
        FileWriter writer=null;
        try {
            //开启写入流
            writer=new FileWriter(dataFileDir+"/PhysiqueData.txt",true);
            writer.write(ConversionScore+"\n");
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                writer.close();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                System.out.println("数据文件已生成");
            }
        }

    }
}
